第10回日本情報オリンピック E - チーズ
提出
WA
code: python
from collections import deque
from copy import deepcopy
h, w, n = map(int, input().split())
for y in range(h):
for x in range(w):
def goal(num):
for y in range(h):
for x in range(w):
def bfs(start, goal, que):
visited_c = deepcopy(visited)
que.append(start)
while (len(que) != 0):
nowY, nowX, dis = que.popleft()
if (nowX < 0 or nowX >= w or nowY < 0 or nowY >= h):
continue
continue
else:
dis += 1
return visited_c[goal0][goal1] ans = 0
que = deque()
for i in range(2, n+1):
print(ans)
解答
code: python
from collections import deque
h, w, n = map(int, input().split())
def bfs(que, dis, maps, h , w):
while que:
nowi, nowj = que.popleft()
nexti, nextj = nowi + i, nowj + j
if nexti < 0 or nexti > h - 1 or nextj < 0 or nextj > w - 1 or disnextinextj != 0 or mapsnextinextj == 'X': continue
else:
return dis
# スタート地点を0, チーズ工場を1以降に
for i in range(h):
for j in range(w):
if mapsij != '.' and mapsij != 'X' and mapsij != 'S': # .X..1
# ....X
# .XX.S
# .2.X.
# print(cheeses) # 2, 4], 0, 4, [3, 1 ans = 0
for i in range(n):
dis = [0 * w for _ in range(h)] res = bfs(que, dis, maps, h, w)
print(ans)
テーマ
メモ
提出
code: python
from collections import deque
h, w, n = list(map(int, input().split()))
q = deque()
visited = [0 * w for _ in range(h)] for i in range(h):
for j in range(w):
q.append((i, j, 1))
while q:
nowi, nowj, dis = q.popleft()
if nowi < 0 or nowi > h-1 or nowj < 0 or nowj > w-1 or visitednowinowj != 0 or areanowinowj == "X": continue
else:
dis += 1
q.append((nowi + 1, j, dis))
q.append((nowi - 1, j, dis))
q.append((nowi, j + 1, dis))
q.append((nowi, j - 1, dis))
print(visited)